package com.example.spring.exercise.controller;

import com.example.spring.exercise.service.RougeService;
import com.example.spring.exercise.service.dto.rouge.BrandData;
import com.example.spring.exercise.service.dto.rouge.RougeInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : zhayh
 * @date : 2021-4-13 09:59
 * @description :
 */

@Api(tags = "第3单元的API")
@RestController
@RequestMapping("/api/rouge")
public class Unit3Controller {
    @Resource
    private RougeService rougeService;

    @GetMapping("/top-brand")
    @ApiOperation(value = "统计平均售价最高的前5个品牌")
    public ResponseEntity<List<BrandData>> getTopBrandData() {
        List<BrandData> brandData = rougeService.getTopBrandData();
        return ResponseEntity.ok(brandData);
    }

    @GetMapping("/search")
    @ApiOperation(value = "按品牌名称和价格区间进行分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brandName", value = "品牌名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "minPrice", value = "价格区间", dataTypeClass = Float.class),
            @ApiImplicitParam(name = "maxPrice", value = "价格区间", dataTypeClass = Float.class),
            @ApiImplicitParam(name = "page", value = "起始页码", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "每页数据", dataTypeClass = Integer.class)
    })
    public ResponseEntity<Page<RougeInfo>> getRougeInfoByBrandAndPrice(String brandName,
                                                                       Float minPrice, Float maxPrice,
                                                                       Integer page, Integer size) {
        Page<RougeInfo> rougeInfos = rougeService.getRougeByBrandAndPrice(brandName,
                minPrice, maxPrice, page, size);
        return ResponseEntity.ok(rougeInfos);
    }
}
